package com.design.xiangyuan;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 库存信息
 * @author ytj
 * @date 2024/11/28 10:29
 */
public class RedisUtil {
    private ScheduledExecutorService scheduledExecutorService=Executors.newScheduledThreadPool(1);
    private AtomicInteger stock=new AtomicInteger(0);

    public RedisUtil(){
        scheduledExecutorService.scheduleAtFixedRate(()->{
            //模拟库存消耗
            stock.addAndGet(1);
        },0,100000,TimeUnit.MICROSECONDS);
    }

    public Integer getUsed(){
        return stock.get();
    }
}
